"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AccountDailyRegister = void 0;
const DaoBase_1 = require("../../src/engine/dao/DaoBase");
const DateUtil_1 = require("../../src/engine/utils/DateUtil");
const MysqlManager_1 = require("../../src/engine/utils/MysqlManager");
class AccountDailyRegister extends DaoBase_1.DaoBase {
    static isExistRecord(date, account) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.getLogDbName());
            let sql = "select * from " + this.Tb_Name + " where account=? and date=? ;";
            let sqlParams = [account, date];
            let results = yield client.queryPromise(sql, sqlParams);
            if (results && results.length > 0) {
                return true;
            }
            else {
                return false;
            }
        });
    }
    static insertAccountDailyRegister(date, account) {
        return __awaiter(this, void 0, void 0, function* () {
            let isExist = yield this.isExistRecord(date, account);
            if (!isExist) {
                let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.getLogDbName());
                let sql = "insert into " + this.Tb_Name + "(date,account) VALUES(?,?) ;";
                let sqlParams = [date, account];
                let results = yield client.queryPromise(sql, sqlParams);
                if (results && results["affectedRows"] > 0) {
                    return true;
                }
                else {
                    return false;
                }
            }
        });
    }
    static getAccountRegister(startDate, endDate) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.getLogDbName());
            let sql = "select * from " + this.Tb_Name + " where date >= ? and date <= ?;";
            let sqlParams = [startDate, endDate];
            let results = yield client.queryPromise(sql, sqlParams);
            return results;
        });
    }
    static clear(delete_time) {
        return __awaiter(this, void 0, void 0, function* () {
            let client = yield MysqlManager_1.MysqlManager.instance.getDb(this.getLogDbName());
            let sql = "delete from " + this.Tb_Name + " where date < ?";
            let sqlParams = [DateUtil_1.default.formatDateStr3(delete_time)];
            yield client.queryPromise(sql, sqlParams);
        });
    }
}
exports.AccountDailyRegister = AccountDailyRegister;
AccountDailyRegister.Tb_Name = "t_accounts_dailyregister";
